﻿using System;
using System.Collections.Generic;
using System.Text;
using TarreOA.TarreOADAL;
using TarreOA.TarreOAModels;

namespace TarreOA.TarreOABLL
{
    public class UserDiarytbService
    {
        //保存日记信息
        public int saveUserDiary(string diaryTitle, string uln, string diaryContent, DateTime sdt)
        {
            UserDiarytbDAO userDiarytbDAO = new UserDiarytbDAO();
            return userDiarytbDAO.saveUserDiary(diaryTitle, uln, diaryContent, sdt);
        }

        //根据日记编号查询日记信息
        public UserDiary findByDiaryId(int did)
        {
            UserDiarytbDAO userDiarytbDAO = new UserDiarytbDAO();
            return userDiarytbDAO.findByDiaryId(did);
        }

        //根据用户登录名查找日记信息
        public List<UserDiary> findByUserLoginName(string uln)
        {
            UserDiarytbDAO userDiarytbDAO = new UserDiarytbDAO();
            return userDiarytbDAO.findByUserLoginName(uln);
        }

        //根据日记编号删除日记信息
        public bool delDiaryInfoByDiaryId(string[] dids)
        {
            int count = 0;
            bool state = false;
            if (dids != null && dids.Length > 0)
            {
                UserDiarytbDAO userDiarytbDAO = new UserDiarytbDAO();
                for (int i = 0; i < dids.Length; i++)
                {
                    userDiarytbDAO.delDiaryByDiaryId(int.Parse(dids[i]));
                    count++;
                }
                if (count == dids.Length)
                {
                    state = true;
                }
                DiaryFileUploadMappingtbService diaryFileUploadMappingtbService = new DiaryFileUploadMappingtbService();
                diaryFileUploadMappingtbService.delAffixFileInfoByDiaryId(dids);
            }
            return state;
        }

        //查询指定时间内的日记信息

        /// <summary>
        /// 员工工作计划查询
        /// </summary>
        /// <param name="txtStart"></param>
        /// <param name="txtEnd"></param>
        /// <param name="txtTitleOne"></param>
        /// <param name="txtTitleTwo"></param>
        /// <param name="txtContentOne"></param>
        /// <param name="txtContentTwo"></param>
        /// <param name="UserLoginName"
        /// <returns></returns>
        public List<UserDiary> findUserDiaryManager(string txtStart, string txtEnd, string txtTitleOne, string txtTitleTwo, string txtContentOne, string txtContentTwo, string userLoginName) {
            UserDiarytbDAO udDAO = new UserDiarytbDAO();
            string sql = "select * from UserDiarytb where UserLoginName='" + userLoginName + "' ";
            if(!"".Equals(txtStart)) {
                sql += "and RegisterTime >= '" + txtStart + " 00:00:00' ";
            }
            if(!"".Equals(txtEnd)) {
                sql += "and RegisterTime <= '" + txtEnd + " 23:59:59' ";
            }
            if(!"".Equals(txtTitleOne)) {
                sql += "and DiaryTitle like '%" + txtTitleOne + "%' ";
            }
            if(!"".Equals(txtTitleTwo)) {
                sql += "and DiaryTitle like '%" + txtTitleTwo + "%' ";
            }
            if(!"".Equals(txtContentOne)) {
                sql += "and DiaryContent like '%" + txtContentOne + "%' ";
            }
            if(!"".Equals(txtContentTwo)) {
                sql += "and DiaryContent like '%" + txtContentTwo + "%'";
            }
            return udDAO.findUserDiaryManager(sql);
        }
    }
}
